package C;

import java.util.Scanner;
import java.util.StringJoiner;

public class C71 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] csv = sc.nextLine().split(",");
        System.out.println(getResult(csv));
    }

    public static String getResult(String[] csv) {
        int length = csv.length;
        String[] ans = new String[length];
        StringJoiner sj = new StringJoiner(",");
        for (int i = 0; i < csv.length; i++) {
            ans[i] = getValue(i,csv);
            sj.add(ans[i]);
        }
        return sj.toString();
    }

    public static String getValue(int i,String[] csv) {
        String s = csv[i];
        //如果不包含引用，直接返回
        if (!s.contains("<")) return s;

        if (s.contains("<"+(char)('A'+i)+">")) return "-1";
        //如果包含，返回 前+引用+后
        String[] oldString = s.split("<");
        return oldString[0]+getValue(oldString[1].charAt(0)-'A',csv)+oldString[1].substring(2);
    }
}
